// import { useRouterStoreHook } from "@/store/modules/router";
import { getFabAlarmMaterialOptions } from "@/api/modules/fab";

/**
 * @description: 获取search配置信息
 * @return {Array<CommonSearch.SearchOption>}
 */
export const useSearchOption = (): Array<CommonSearch.SearchOption> => {
  // const tabSearchRouterStore = useRouterStoreHook();

  const deviceId: CommonSearch.SearchOption = {
    label: "机台编号",
    key: "deviceId",
    value: "",
    type: "input",
    placeholder: "请输入机台编号",
    span: 5
  };

  const alarmLevel: CommonSearch.SearchOption = {
    label: "报警级别",
    key: "alarmLevel",
    value: null,
    type: "select",
    typeCode: "FAB_ALARM_LEVEL",
    placeholder: "请选择报警级别",
    span: 5
  };

  const materialCode: CommonSearch.SearchOption = {
    label: "物料",
    key: "materialCode",
    value: null,
    type: "select",
    remote: true,
    selectRemoteApi: getFabAlarmMaterialOptions,
    getParams: (materialName: string) => ({ materialName }),
    mapOption: ({ code: value = "", name: label = "" }: any) => ({ value, label }),
    placeholder: "请选择物料",
    span: 5
  };

  //  暂时先隐藏 2024-8-28
  // const alarmType: CommonSearch.SearchOption = {
  //   label: "类别",
  //   key: "alarmType",
  //   value: null,
  //   type: "select",
  //   typeCode: "FAB_ALARM_TYPE",
  //   placeholder: "请选择报警类别"
  // };

  // const alarmSource: CommonSearch.SearchOption = {
  //   label: "来源",
  //   key: "alarmSource",
  //   value: null,
  //   type: "select",
  //   typeCode: "FAB_ALARM_SOURCE",
  //   placeholder: "请选择报警来源"
  // };

  const alarmTimeStart: CommonSearch.SearchOption = {
    label: "日期",
    key: "alarmTimeStart",
    realKeys: ["alarmTimeStart", "alarmTimeEnd"],
    value: [],
    type: "datetimerange",
    span: 6
  };

  return [deviceId, alarmLevel, materialCode, alarmTimeStart];
};

/**
 * @description: 获取table表格的表头（cloumns）信息
 * @return {*}
 */
export const useTableCloumns = (cb?: (scope: any) => void): Array<CommonTable.TableCloumnsType> => {
  return [
    {
      label: "机台编号",
      prop: "deviceId",
      width: 120,
      cloumnClick(scope: any) {
        cb && cb(scope);
      }
    },
    // {
    //   label: "告警编号",
    //   prop: "alarm_id",
    //   width: 160
    // },
    {
      label: "详细信息",
      prop: "alarmMsg",
      width: 220
    },
    {
      label: "级别",
      prop: "alarmLevel",
      width: 100,
      render(scope) {
        const {
          row: { alarmLevel = "" }
        } = scope;
        const colors = new Map([
          [
            "ALARM_ONE",
            {
              label: "一级",
              backgroundColor: "#EF4444FF"
            }
          ],
          [
            "ALARM_TWO",
            {
              label: "二级",
              backgroundColor: "#FF781BFF"
            }
          ],
          [
            "ALARM_THREE",
            {
              label: "三级",
              backgroundColor: "#F2B119FF"
            }
          ]
        ]);
        const c = colors.get(alarmLevel) || {};
        const styleFn = () => {
          const style = {
            display: "flex",
            alignItems: "center",
            justifyContent: "center",
            padding: "4px 10px",
            borderRadius: "4px",
            lineHeight: 1,
            fontSize: "12px",
            color: "#fff",
            backgroundColor: "#e9e9eb"
          };
          return { ...style, ...c };
        };
        return () => (
          <div style={{ display: "flex", alignItems: "center", justifyContent: "center", height: "100%" }}>
            <div style={styleFn()}>{c?.label || alarmLevel}</div>
          </div>
        );
      }
    },
    {
      label: "类型",
      prop: "alarmType",
      width: 150
    },

    {
      label: "时间",
      prop: "alarmTime",
      width: 180
    }
  ];
};
